package com.boboPlanet.comm.feign.fallback;

import com.boboPlanet.comm.entity.po.FileDetailPO;
import com.boboPlanet.comm.feign.PlanetFileApi;
import com.boboPlanet.comm.result.ResponseResult;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @Description: TODO
 * @Author: mis_wu
 * @Date: 2023/7/11
 * @Company xxx
 **/
@Component
@Slf4j
public class PlanetFileApiFallbackImpl implements FallbackFactory<PlanetFileApi> {

    @Override
    public PlanetFileApi create(Throwable cause) {
        return new PlanetFileApiImpl(cause);
    }

    public static class PlanetFileApiImpl implements PlanetFileApi{

        private final Throwable throwable;

        public PlanetFileApiImpl(Throwable throwable){
            this.throwable = throwable;
        }

        @Override
        public ResponseResult<Boolean> saveFile(FileDetailPO fileDetail) {
            log.error("feign调用失败,保存上传文件记录失败,方法:saveFile,参数: {},异常：{}",fileDetail,throwable.getMessage(),throwable);
            return ResponseResult.error("保存上传文件记录失败,请联系管理员");
        }

        @Override
        public ResponseResult<FileDetailPO> getFileByUrl(String url) {
            log.error("feign调用失败,获取上传文件记录失败,方法:getFileByUrl,参数: {},异常：{}",url,throwable.getMessage(),throwable);
            return ResponseResult.error("获取上传文件记录失败,请联系管理员");
        }

        @Override
        public ResponseResult<Boolean> deleteFileById(Long id) {
            log.error("feign调用失败,删除上传文件记录失败,方法:deleteFileById,参数: {},异常：{}",id,throwable.getMessage(),throwable);
            return ResponseResult.error("删除上传文件记录失败,请联系管理员");
        }
    }
}
